package com.zz.inventory.controller;

import lombok.RequiredArgsConstructor;
import com.zz.inventory.service.DIfyService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequiredArgsConstructor
public class DifyClientController {
    private final DIfyService dIfyService;

    @GetMapping(value = "/api/stream",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @CrossOrigin(origins = "http://localhost:81")
    public Flux<String> stream(@RequestParam("userPrompt") String userPrompt,
                               @RequestParam(value = "user",defaultValue = "abc") String user){
        return dIfyService.getStream(userPrompt,user);
    }
}
